package com.oromwin.repos.common.helper;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import com.oromwin.repos.common.Common.CharSet;

public class IOHelper {

    public static void writeUTF8(DataOutputStream dos, String str) throws IOException {
        if (str == null) str = "null";
        int len = str.getBytes(CharSet.UTF8).length;
        dos.writeInt(len);
        dos.write(str.getBytes(CharSet.UTF8));
    }

    public static String readUTF8(DataInputStream dis) throws IOException {
        int off = 0;
        int len = dis.readInt();
        byte[] b = new byte[len];
        dis.read(b, off, len);
        String str = new String(b, CharSet.UTF8);
        return str;
    }

}
